package com.tepth.vehiclemaintenance.ui.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.tepth.vehiclemaintenance.R;
import com.tepth.vehiclemaintenance.ui.view.loading.AVLoadingIndicatorView;
import com.tepth.vehiclemaintenance.ui.view.loading.BallSpinFadeLoaderIndicator;

/**
 * Created by zhangyu on 2017/5/11.
 */

public class LoadingFrameLayout extends FrameLayout {
    private View mViewEmpty;
    private View mViewLoading;
    private View mViewError;

    public LoadingFrameLayout(@NonNull Context context) {
        super(context);
        init();
    }

    public LoadingFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        mViewEmpty = LayoutInflater.from(getContext()).inflate(R.layout.view_empty, null);
        mViewLoading = LayoutInflater.from(getContext()).inflate(R.layout.view_loading, null);
        AVLoadingIndicatorView avi = (AVLoadingIndicatorView) mViewLoading.findViewById(R.id.avi);
        BallSpinFadeLoaderIndicator indicator = new BallSpinFadeLoaderIndicator();
        avi.setIndicator(indicator);
    }

    public void showLoading() {
        removeView(mViewEmpty);
        addView(mViewLoading, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
    }

    public void showEmpty() {
        removeView(mViewLoading);
        addView(mViewEmpty, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
    }

    public void showContent() {
        removeView(mViewLoading);
        removeView(mViewEmpty);
    }
}
